<?php $i = (intval($_GET['i'])==0) ? 1 : intval($_GET['i']); ?>
<script type="text/javascript">
status(<?php echo ((12.5 * $i) - 13); ?>,<?php echo (12.5 * $i); ?>,5);
</script>
<?php

/**
 * @author Martin Pernica
 * @copyright 2009
 */
echo "\n<h2>Instalace</h2>";

echo "\n<br />";
echo "\n<p>		Instalační proces:</p>";
echo "\n<p>		<strong>" . $_SESSION['realPath'] . "</strong></p>";

function printRefresh($i, $time){
	echo '<meta http-equiv="refresh" content="'.$time.';url=index.php?p=6&i='.$i.'">';
}

if ($_SESSION['step5']) {
    
    if ($i == 1) {
        $q = VInstallater::ExuteSql('./sql/main.sql', "file");
        VInstallater::AddLogMessage("základní tabulky", (bool)$q);
        printRefresh($i+1, '7');
    } elseif ($i == 2) {
        $q = "INSERT INTO `{prefix}setting` VALUES ('1', 'czech', 'content', 'VisionCMS', '...new vision for your path', 'utf-8', null, null, null, 'vision', '1', 'aqua', 'default', 'MooEditable');";
        $q = VInstallater::ExuteSql($q, "text");
        VInstallater::AddLogMessage("nastavení systému", (bool)$q);
        printRefresh($i+1, '7');
    } elseif ($i == 3) {
        $q = "INSERT INTO `{prefix}forum_konfigurace` (`id`, `prispevku`, `temat`, `pristupnost`, `template`) VALUES
(1, 5, 50, 0, 'default');";
        $q = VInstallater::ExuteSql($q, "text");
        VInstallater::AddLogMessage("nastavení fóra", (bool)$q);
        printRefresh($i+1, '7');
    } elseif ($i == 4) {
        $q = "INSERT INTO `{prefix}categories` VALUES ('1', 'Nekategorizováno', 'Články bez kategorie', '1');\n
				INSERT INTO `{prefix}sections` VALUES ('1', 'Hlavní', 'Hlavní sekce');";
        $q = VInstallater::ExuteSql($q, "text");
        VInstallater::AddLogMessage("nastavení kategorií a sekcí", (bool)$q);
        printRefresh($i+1, '7');
    } elseif ($i == 5) {
        $q = "INSERT INTO `{prefix}permissions` VALUES ('1', 'com_content', '3', '0');\n
				INSERT INTO `{prefix}permissions` VALUES ('2', 'com_categories', '3', '0');\n
				INSERT INTO `{prefix}permissions` VALUES ('3', 'com_comment', '2', '0');\n
				INSERT INTO `{prefix}permissions` VALUES ('4', 'com_custom', '3', '0');\n
				INSERT INTO `{prefix}permissions` VALUES ('5', 'com_forum', '2', '0');\n
				INSERT INTO `{prefix}permissions` VALUES ('6', 'com_poll', '3', '0');\n
				INSERT INTO `{prefix}permissions` VALUES ('7', 'com_user', '4', '0');";
        $q = VInstallater::ExuteSql($q, "text");
        VInstallater::AddLogMessage("nastavení oprávnění", (bool)$q);
        printRefresh($i+1, '7');
    } elseif ($i == 6) {

        $hash = new Hash($_SESSION['adminUsername'], $_SESSION['adminPass']);
        $hash->hash();


        $q = "INSERT INTO `{prefix}users` VALUES ('1', '" . $_SESSION['adminUsername'] .
            "', '" . $hash->password . "', '" . $hash->salt .
            "', 'Administrátor', '4', '0', '" . $_SESSION['adminEmail'] .
            "', '0', 'default.png', '0', 'http://', NOW(), '0000-00-00', 'male', 'Administrátor');";
        $q = VInstallater::ExuteSql($q, "text");
        VInstallater::AddLogMessage("správcovský účet", (bool)$q);
        printRefresh($i+1, '7');
    } elseif ($i == 7) {
    	
    	if($_SESSION['seo'] == 1){
    		$seo = (string)"true";
    	}else{
    		$seo = (string)"false";
    	}
    	
    	$string = '
<?php
$config["contact"]["email"]   = "' . $_SESSION['adminEmail'] . '";'."\n\r".'
$config["mysql"]["type"]      = "mysqli";'."\n\r".'
$config["mysql"]["server"]    = "' . $_SESSION['mysql']['host'] . '";'."\n\r".'
$config["mysql"]["username"]  = "' . $_SESSION['mysql']['user'] . '";'."\n\r".'
$config["mysql"]["passwd"]    = base64_decode( \'' . base64_encode($_SESSION['mysql']['pass']) .'\' );'."\n\r".'
$config["mysql"]["db_name"]   = "' . $_SESSION['mysql']['db'] . '";'."\n\r".'
$config["mysql"]["db_prefix"] = "' . $_SESSION['mysql']['prefix'] . '";'."\n\r".'
$config["ftp"]["server"]    = "' . $_SESSION['ftp']['host'] . '";'."\n\r".'
$config["ftp"]["username"]  = "' . $_SESSION['ftp']['user'] . '";'."\n\r".'
$config["ftp"]["passwd"]    = base64_decode( \'' . base64_encode($_SESSION['ftp']['pass']) .'\' );'."\n\r".'
$GLOBALS["seo"] = '.$seo.';'."\n\r".'
$env_ready = 1;'."\n\r".'
?>';
    	
    	if($_SESSION['env_nowrite']){
    		$_SESSION['env'] = $string;
    		$q = false;
    	}else{

        $filename = "../env.php";
        

        $fp = fopen($filename, "w");
        fwrite($fp, $string);
        $q = fclose($fp);
        
        
        }
        VInstallater::AddLogMessage("env.php", (bool)$q);
        printRefresh($i+1, '7');
    } elseif ($i == 8) {
    	if($_SESSION['sample_data'] == 1){
    		$q = VInstallater::ExuteSql('./sql/ext.sql', "file");
    		VInstallater::AddLogMessage("ukázkové data", (bool)$q);
    	}else{
    		VInstallater::AddLogMessage("dokončuji", (bool)true);
    	}
        echo '<meta http-equiv="refresh" content="7;url=index.php?p=7">';
    }

?>
<div style="text-align: left;">
<div class="statusbar">
<div id="bar"></div>
<div id="status">0%</div>
</div>
</div>
<br />
<p class="msg warning">Během instalace nezavírejte prohlížeč !
 Můžete dojít k závažným chybám na vašem webu !</p>
<?php

} else {
    echo "\n<p class=\"msg error\">Souhrn není platný !</p>";
}

$menu = "<li class=\"done\"> 1. Kontrola</li>\n
<li class=\"done\">2. Licence</li>\n
<li class=\"done\"> 3. Nastavení</li>\n
<li class=\"done\"> 4. Účet správce</li>\n
<li class=\"done\"> 5. Přehled</li>\n
<li class=\"now\"> 6. Instalace</li>\n
<li> 7. Výsledek instalace</li>\n";
$buttons_left .= VInstallater::PrintButton("cancel-inactive");

$buttons_right .= VInstallater::PrintButton("right-inactive");
?>